package com.mdd.admin.controller.system;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.system.ISystemDevPayService;
import com.mdd.admin.validate.system.SystemDevPayParam;
import com.mdd.admin.validate.system.SystemWxPayConfigParam;
import com.mdd.admin.vo.system.SystemDevPayDetailVo;
import com.mdd.admin.vo.system.SystemDevPayListVo;
import com.mdd.admin.vo.system.SystemDevWxPayDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 支付配置管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/system/pay")
public class SystemDevPayController {

    @Resource
    ISystemDevPayService iSystemDevPayService;

    /**
     * 支付配置列表
     *
     * @author panweiliang
     * @return Object
     */
    @GetMapping("/list")
    public Object list() {
        List<SystemDevPayListVo> list = iSystemDevPayService.list();
        return AjaxResult.success(list);
    }
    /**
     * 支付配置详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/wx/detail")
    public Object wxDetail(@Validated @IDMust() @RequestParam("id") Integer id) {
        SystemDevWxPayDetailVo detail = iSystemDevPayService.getWxPayConfigDetail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 支付配置新增
     *
     * @author panweiliang
     * @param systemWxPayConfigParam 参数
     * @return Object
     */
    @Log(title = "设置微信支付配置")
    @PostMapping("/wx/setup")
    public Object wx_setup(@Validated(value = SystemWxPayConfigParam.create.class) @RequestBody SystemWxPayConfigParam systemWxPayConfigParam) {
        iSystemDevPayService.updateWxPayConfig(systemWxPayConfigParam);
        return AjaxResult.success();
    }

    /**
     * 余额支付配置详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/balance/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        SystemDevPayDetailVo detail = iSystemDevPayService.getBalanceDetail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 余额支付配置编辑
     *
     * @author panweiliang
     * @param systemDevPayParam 参数
     * @return Object
     */
    @Log(title = "设置微信支付配置")
    @PostMapping("/balance/setup")
    public Object balance_setup(@Validated(value = SystemDevPayParam.create.class) @RequestBody SystemDevPayParam systemDevPayParam) {
        iSystemDevPayService.updateBalance(systemDevPayParam);
        return AjaxResult.success();
    }

}
